#include<iostream>
#include<cstring>
#include<string>

using namespace std;

int check_str_0(char *str,int size,bool *is_unique);

int check_str_1(string str,bool *is_unique);

int check_str_1(string str,bool *is_unique)
{
/*
    Parameters:
    1. str(In): The string object, which contains the string to check.
    2. is_unique(Out): The bool variable. If str contains all unique characters, is_unique is set to True; Otherwise, is_unique is set to False.

    Return value:
    Return 1, if there are errores in this function.
    Return 0, if there is no error in this function.

    Logic:
    1. Initialize a flag array, whose size is 256.
    2. Check the string one by one.
*/
    int flag[256];
    int temp;
    // 1. Initialize the flag array.
    for(int i=0;i<256;i++)
        flag[i]=0;
    
    for(size_t i=0; i<str.size(); i++)
    {
        temp=str[i];
        if(temp<0)
        {
            cout<<"There is an error in the input string."<<endl;
            return 1;
        }
        if(1==flag[temp])
        {
            *is_unique=false;
            return 0;
        }
        else
	    flag[temp]=1;
    }
    *is_unique=true;
    return 0;
}

int check_str_0(char *str, int size,bool *is_unique)
{
/*
    Parameters: 
    1. str(In): The pointer to the string to be checked.
    2. size(In): The length of this string.
    3. is_unique(Out): a pointer to a boolean variable. If str contains all unique characters, is_unique is set to True; Otherwise, is_unique is set to False.
    
    Return value: 
    Return 1, if there are errores in this function.
    Return 0, if there is no error in this function.

    Logic:
    1. Check the validation of parameters.
    2. Initialize a flag array.
    3. Perform the unique checking.
*/
    int flag[256]; 
    int temp;

    // 1. Check the arguments.
    if(NULL==str || 0==size)
    {
        // empty string also contains unique chars.
        *is_unique=true;
        return 0;
    }    
    if(size < 0)
    {
        cout<<"The number of elements in this string is invalid.\n";
        return 1;
    }
    // 2. Initialize the flag array.
    for(int i=0; i<256;i++)
    {
        flag[i]=0;
    }
    // 3. Perform the unique checking.
    for(int i=0; i<size;i++)
    {
        temp=(int)(*(str+i));
        if(temp<0 || temp>255)
        {
            cout<<"There is invalid characters in this string.\n";
            return 1;
        }
        if(flag[temp]==1)
        {
            *is_unique=false;
            return 0;
        }
        else
            flag[temp]=1;
    }
    
    *is_unique=true;
    return 0;  
}

int check_str_0()
{
    int num_cases;
    bool result;   
    char str[1024];

    // read in the number of test cases in this file.
    cin>>num_cases;
    cin.ignore();
    for(int i=0;i<num_cases;i++)
    {
        memset(str,0,1024);
        cin.getline(str,1024);

        if(check_str_0(str,strlen(str),&result))
        {
            cout<<"There is an error in check_str function, the current string is NO."<<i<<"  "<<str<<endl;
            return 1;
        }
        
        cout<<result<<endl;    
    }
    return 0;
}
int check_str_1()
{
    int num_cases;
    bool result;   

    string str;
    cin>>num_cases;
    cin.ignore();  
    for(int i=0;i<num_cases;i++)
    {
        str.clear();
        getline(cin,str);
        if(check_str_1(str,&result))
        {
            cout<<"There is an error in check_str function, the current string is NO."<<i<<"  "<<str<<endl;
            return 1;
        }
        
        cout<<result<<endl;    
    }
    
    return 0;

}
int main()
{
    
    // return check_str_0();
    int ret;
    ret=check_str_1();
    return ret;
}


